package com.etime.service.impl;

import com.etime.mapper.StationMapper;
import com.etime.pojo.Station;
import com.etime.service.StationService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StationServiceImpl implements StationService {
    @Autowired
    private StationMapper stationMapper;
    @Override
    public PageInfo<Station> getStationByPage(Integer page) {
        PageHelper.startPage(page,5);
        List<Station> list=stationMapper.getAllStation();
        PageInfo<Station> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public PageInfo<Station> getStationByName(Integer page, String station_name) {
        PageHelper.startPage(page,5);
        List<Station> list=stationMapper.getStationByName("%"+station_name+"%");
        PageInfo pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public boolean addStation(Station station) {
        int rows = stationMapper.addStation(station);
        if (rows == 0) {
            //新增失败
            return false;
        } else {
            return true;
        }
    }

    @Override
    public Station getStationById(Integer station_id) {
        return stationMapper.getStationById(station_id);
    }

    @Override
    public boolean ediStation(Station station) {
        int rows = stationMapper.editStation(station);
        if(rows==0){
            return false;
        }else{
            return true;
        }
    }

    @Override
    public List<Station> getAllStation() {
        return stationMapper.getAllStation();
    }

}
